package summer_vacation.xuejiahua;

/**编程求下列式子的值，y＝1-1/2+1/3-1/4+…+1/99-1/100，并将结果输出，格式为: 1-1/2+1/3-1/4+…+1/99-1/100 = 表达式的值
 * Created by Administrator on 2015/8/28.
 */
public class java_19 {

    public static void main(String[] args) {

    double result=1;

        double a=1;
    int num=100;
    for(int i=2;i<=num;i++){
        if(i%2==0){
            result=result-(a/i);
        }
        else{
            result=result+(a/i);
        }
    }
    System.out.println("最后结果是："+result);
}
}
